package TrafficSim;

public class TrafficLight {
	
	private int id;
	private State tlState;
	private boolean debug = false;
	
	public static enum State {RED, YELLOW, REDYELLOW, GREEN, OFF, BLINK}

	public TrafficLight(int id){
		this.id = id;
	}
	
	public State getTlState() {
		return tlState;
	}
	
	public int getId() {
		return id;
	}

	public void setRed(){
		tlState = State.RED;
		if (debug == true){
			System.out.println(this.id + ": red");
		}
	  }
	  
	   public void setRedYellow(){
		   tlState = State.REDYELLOW;
		   if (debug == true){
		   System.out.println(this.id + ": redYellow");
		   }
	  }
	  
	   public void setGreen(){
		   tlState = State.GREEN;
		   if (debug == true){
		   System.out.println(this.id + ": green");
		   }
	  }
	  
	   public void setYellow(){
		   tlState = State.YELLOW;
		   if (debug == true){
		   System.out.println(this.id + ": yellow");
		   }
	  }
	  
	  public void setBlink(){
		  tlState = State.BLINK;
		  if (debug == true){
		  System.out.println(this.id + ": blink");
		  }
	  }
	  
	  public void turnOff(){
		  tlState = State.OFF;
		  if (debug == true){
		  System.out.println(this.id + ": off");
		  }
	  }
	  
	  public void switchState(){
	      if (tlState==State.RED){
	         setRedYellow();
	       }
	       else if (tlState==State.REDYELLOW){
	          setGreen();
	       }
	       else if (tlState==State.GREEN){
	          setYellow();
	       }
	       else{
	          setRed();
	       }         
	    }
}
